function sendAjax(url,type,data,fn){
    $.ajax({
        url,
        type,
        data,
        success:fn
    });
}
function sendAuthAjax(url,type,data,fn,loginUrl='./login.html'){
    //本地获取token
    let token = localStorage.getItem('token');
    if (token) {
        $.ajax({
            url,
            type,
            headers: {
                Authorization: 'Bearer '+token
            },
            data,
            success:fn,
            error:function(){
                //鉴权失败
                alert('鉴权失败!登录失效，请重新登录！');
                location.href=loginUrl;
            }
        })
    }else{
        location.href=loginUrl;
    }
}
export {
    sendAjax,
    sendAuthAjax
}